﻿@using System.Text
@using OA.Model
@using OA.AspNetCore.Html
@using OA.Core
@using OA.Core.Model
@using OA.Core.Helper

@model List<OA.Model.VoteItem>
 
@{
    Layout = "~/Areas/Member/Views/Shared/_Layout.cshtml";
    Vote infoVote = ViewBag.Vote;
    List<EmployeeVoteSelect> listResult = ViewBag.Result;
}
<style type="text/css">
    .content_vote {
        height: 300px;
        width: 600px;
    }

    .VoteTitle {
        width: 100%;
        text-align: center;
        font-size: 32px;
    }

    .VoteTime {
        margin-top: 10px;
        width: 100%;
        text-align: center;
        font-size: 14px;
        color: red;
    }

    .Items {
        margin-top: 60px;
    }
</style>
<script type="text/javascript" src="~/Content/js/echarts.common.min.js"></script>

 
<div class="layui-tab layui-tab-brief" lay-filter="user">
    @{
        char[] chars = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P' };
        Type t = typeof(VoteItemType);
    }
    <p class="VoteTitle">@infoVote.Title</p>
    <p class="VoteTime">@infoVote.StartTime--@infoVote.EndTime</p>
    <div class="Items">
        @for (int i = 0; i < Model.Count; i++)
        {
            int temp = i + 1;
            VoteItem item = Model[i];
            if (item.Type == 3) { continue; }
            StringBuilder sbSubTitle = new StringBuilder();
            if (string.IsNullOrWhiteSpace(item.ItemContent)) { item.ItemContent = ""; }
            List<string> options = item.ItemContent.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries).ToList();

            string titleIndex = $"第{temp}题";
            var result = listResult.Where(m => m.VoteItemID == item.ID).ToList();
            Dictionary<string, int> dicResult = new Dictionary<string, int>();
            string jsContent = string.Empty;
            if (item.Type == 1)
            {
                jsContent = $"myChart_{i}.setOption(option_{i});";
            }
            else
            {
                jsContent = $"myChart_{i}.setOption(option_{i});";
            }
            foreach (EmployeeVoteSelect itemResult in result)
            {
                if (!string.IsNullOrWhiteSpace(itemResult.Options))
                {
                    itemResult.MyOptions = itemResult.Options.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).ToList();
                    foreach (string Options in itemResult.MyOptions)
                    {
                        int selectIndex = 0;
                        if (!Int32.TryParse(Options, out selectIndex))
                        {
                            continue;
                        }
                        if (selectIndex > options.Count)
                        {
                            continue;
                        }
                        string selectContent = chars[selectIndex - 1].ToString() + ":" + options[selectIndex - 1];
                        selectContent = selectContent.ToSubstring(10);
                        if (dicResult.ContainsKey(selectContent))
                        {
                            dicResult[selectContent] += 1;
                        }
                        else
                        {
                            dicResult.Add(selectContent, 1);
                        }
                    }
                }
            }
            <div style="margin:30px;height:350px;">
                <p><span style="padding-right:6px;">[@MyEnum.GetEnumNameByValue(item.Type, t)]</span>@titleIndex：@item.Title</p>
                <div style="width:600px;clear:both;position:relative;height:200px;">
                    <div class="content_vote" id="item_@i"></div>
                </div>
            </div>
            if (item.Type == 1)
            {
                <script type="text/javascript">
                       var myChart_@i = echarts.init(document.getElementById('item_@i'));
                            var option_@i = {
                            tooltip: {
                                trigger: 'item',
                                formatter: "{a} <br/>{b} : {c} ({d}%)"
                            },

                            series:  [
                                {
                                    name: '选择数',
                                    type: 'pie',
                                    radius: '55%',
                                    data:@Html.Raw(dicResult.ToListJson())
                                }
                            ]
                        };
                        @Html.Raw(jsContent)
                </script>
            }
            else
            {
                <script type="text/javascript">
                            var myChart_@i = echarts.init(document.getElementById('item_@i'));
                            var option_@i = {
                                tooltip: {},
                                xAxis: {
                                    data: @Html.Raw(dicResult.GetKeyList())
                                },
                                legend: {
                                    orient: 'vertical',
                                    x: 'left',
                                    data: @Html.Raw(dicResult.GetKeyList())
                                },
                                yAxis: {},
                                series: [{
                                    name: '选择数',
                                    type: 'bar',
                                    data: @Html.Raw(dicResult.GetValueList())
                                }]
                            };
                             @Html.Raw(jsContent)
                </script>
            }

        }
    </div>
</div>